public class UdpData {
    private static  byte MSG_TYPE = 0x01;
    private static  byte MSG_VER = 0x01;
    private static  byte[] MSG_IDX = new byte[4];
    private static  byte[] MSG_SIZE = new byte[2];
    private static  byte[] DEV_ID = new byte[8];

    /**
     1Byte	MSG_TYPE
     1Byte	MSG_VER
     4Byte	MSG_IDX
     2byte	MSG_SIZE
     8byte  DEV_ID

     MSG_VER :  本协议的版本号 ，后续可能升级协议用，格式X.Y，X为高4位，Y为低4位
     MSG_IDX : 协议包 索引号，相当于帧号 ，初始化为0，
     MSG_SIZE : 消息长度， 2 byte
     DEV_ID :  为终端设备ID号，15位数字， 字符串转为长整形 为 8位
     */

    private static byte[] getMsgHead(){
        byte[] msgHead = new byte[16];
        msgHead[0] = MSG_TYPE;
        msgHead[1] = MSG_VER;

        for (int i = 0; i < MSG_IDX.length; i++) {
            MSG_IDX[i] = 0x00;
        }
        System.out.println("msg_idx: " + MSG_IDX.length);
        int msgLength = 0xffff;
        byte[] bytes = intToByteArray(msgLength);
        System.out.println("changdu:" + bytes.length);
        return msgHead;
    }

    public static byte[] intToByteArray(int i) {
        byte[] result = new byte[4];
        //由高位到低位
        result[0] = (byte)((i >> 24) & 0xFF);
        result[1] = (byte)((i >> 16) & 0xFF);
        result[2] = (byte)((i >> 8) & 0xFF);
        result[3] = (byte)(i & 0xFF);
        return result;
    }

    public static void main(String[] args) {
        getMsgHead();
    }
}
